<?php

use Jialeo\LaravelSchemaExtend\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateRepayRecordsTable extends Migration
{
    private $table = 'repay_records';

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create($this->table, function (Blueprint $table) {
            $table->charset = 'utf8';
            $table->collation = 'utf8_general_ci';
            $table->comment = '还款分期记录表';
            $table->increments('id');
            $table->unsignedInteger('uid')->comment('关联用户id');
            $table->unsignedInteger('summary_id')->comment('关联还款表id');
            $table->unsignedInteger('bank_cards_id')->comment('关联user_bank_cards银行卡id');
            $table->unsignedTinyInteger('period')->comment('当前期数,0为全部还清记录');
            $table->unsignedInteger('amount')->default(0)->comment('应还款金额/本金,以分为单位');
            $table->unsignedTinyInteger('status')->default(1)->comment('还款状态 1:待还／未还,2:还款中,3:还款失败,4:还款成功(以资方还款接口为准)');
            $table->unsignedTinyInteger('failure_status')->default(0)->comment('还款失败细分状态 1:月报接口失败,2:公共接口失败,3:资方接口失败');
            $table->string('failure_message', 255)->default('')->comment('还款失败原因');
            $table->unsignedTinyInteger('pay_off')->default(1)->comment('是否全部还清 1:分期还款,2:全部还清');
            $table->date('normal_date')->nullable()->comment('本期正常还款日期');
            $table->date('repay_date')->nullable()->comment('本期真实还款日期(以资方接口成功事件为准)');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists($this->table);
    }
}
